# parse config files and Check if the parameters are legal
import json

def parse_json_config(json_file):
    with open(json_file) as f:
        decoded_dict = json.loads(f.read())
    assert "gene_list" in decoded_dict
    assert "flexible_parameters" in decoded_dict
    assert decoded_dict["flexible_parameters"]["file_type"] in ["csv","table"],"flexible_parameters file_type must be table or csv"
    assert decoded_dict["flexible_parameters"]["cluster_method"] in ["leiden","louvain"], "flexible_parameters cluster_method must be leiden or louvain"
    assert decoded_dict["flexible_parameters"]["doublet_method"] in ["scvi","scrublet"], "flexible_parameters doublet_method must be scvi or scrublet"
    assert decoded_dict["flexible_parameters"]["diff_method"] in ["t-test","t-test_overestim_var","wilcoxon"], "flexible_parameters diff_method must be scvi or scrublet"
    return decoded_dict

def print_config(decoded_dict):
    print("Parameters in configuration file:")
    for cat1 in decoded_dict:
        if type(decoded_dict[cat1]) == dict:
            print(cat1)
            for cat2 in decoded_dict[cat1]:
                print("\t", cat2, ":", decoded_dict[cat1][cat2])
        else:
            print(cat1, ":", decoded_dict[cat1])

if __name__ == "__main__":
    decoded_dict = parse_json_config("config_scanpy_pipeline.json")
    print_config(decoded_dict)